package com.service;

import java.util.List;

import com.bean.ChatBean;
import com.bean.SessionBean;
import com.bean.TwoTuple;
import com.dao.impl.ChatDao;
import com.dao.impl.SessionDao;

public class FeedbackService {
	private SessionDao sessionDao;
	private ChatDao chatDao;
	
	//值班员第一次发表意见 创建话题 提交第一次发言
	public int launchFeedback(SessionBean sessionBean, ChatBean chatBean){
		int ret = 0;
		ret = sessionDao.insertTopic(sessionBean);
		if(ret > 0){
			chatBean.setSessionID(ret);
			chatBean.setSequence(1);
			ret = chatDao.insertChat(chatBean);
		}
		return ret;
	}
	
	//值班员查看意见箱 
	public TwoTuple<Integer, List<SessionBean>> getSessionByStaff(String ename, int offset, int rows){
		return sessionDao.getSessionByStaff(ename, offset, rows);
	}
	
	//主任查看意见箱
	public TwoTuple<Integer, List<SessionBean>> getSessionByDirector(int offset, int rows){
		return sessionDao.getSessionByDirector(offset, rows);
	}
	
	public TwoTuple<Integer,List<SessionBean>> getPublicSession(int offset, int rows){
		return sessionDao.getPublicSession(offset, rows);
	}
	
	//查看讨论记录
	public List<ChatBean> inquireChatDetail(int sessionid, int role){
		List<ChatBean> list = null;
		if(role == 1){
			sessionDao.updateStaffUnread(sessionid, 0);
		}else{
			sessionDao.updateDirectorUnread(sessionid, 0);
		}
		list = chatDao.queryChatDetail(sessionid);
		return list;
	}
	
	//回复讨论意见
	public int reply(int sessionid, int role, ChatBean bean){
		int ret = 0;
		if(role == 1){
			sessionDao.updateDirectorUnread(sessionid, 1);
		}else{
			sessionDao.updateStaffUnread(sessionid, 1);
		}
		int sequence = chatDao.queryChatLayer(sessionid);
		bean.setSequence(++sequence);
		ret = chatDao.insertChat(bean);
		return ret;
	}
	
	//主任删意见
	public int delTopic(int id){
		return sessionDao.delTopic(id);
	}
	
	
	
	
	public SessionDao getSessionDao() {
		return sessionDao;
	}
	public void setSessionDao(SessionDao sessionDao) {
		this.sessionDao = sessionDao;
	}
	public ChatDao getChatDao() {
		return chatDao;
	}
	public void setChatDao(ChatDao chatDao) {
		this.chatDao = chatDao;
	}
	
	
}
